<?php
    define('WP_USE_THEMES', false); 
    
    require('./wp-blog-header.php');
    require('./DBHandler.php');

    $dbHandler = new DBHandler;
?>

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8" />
        <title></title>
    </head>
    <body>
        <h2>Manage Courses</h2>
        <a href="managecourse.php">Add new course</a>
        <br/><br/>
        <table border="1">
            <tr>
                <th>Name</th>
                <th>Quarter</th>
                <th>Year</th>
                <th>Faculty</th>
                <th>Edit</th>
                <th>Delete</th>
            </tr>
            <?php
                $rows = $dbHandler->GetAllCourses();

                if ($rows)
                {
                    foreach($rows as $row)
                    {
                        echo "<tr>";
                        echo "<td>" . $row->Name . "</td>";
                        echo "<td>" . $row->Quarter . "</td>";
                        echo "<td>" . $row->Year . "</td>";
                        echo "<td>" . $row->FacultyName . "</td>";
                        echo "<td><a href='managecourse.php?op=edit&id=" . $row->Id . "'>Edit</a></td>";
                        echo "<td><a href='managecourse.php?op=delete&id=" . $row->Id . "'>Delete</a></td>";
                        echo "</tr>";
                    }
                } 
                else
                {
                    echo "<tr><td colspan=6>No courses found.</td></tr>";
                }
            ?>
        </table>
    </body>
</html>
